// 策略接口
public interface PayStrategy {
    boolean pay(int paymentAmount);
}

// 具体策略 - 信用卡付款方式
public class CreditCardPayment implements PayStrategy {

    private String name;
    private String cardNumber;

    public CreditCardPayment(String fullName, String ccpayment) {
        this.name = fullName;
        this.cardNumber = ccpayment;
    }

    @Override
    public boolean pay(int amountDue) {
        System.out.println(amountDue + " paid with credit/debit card");
        return true;
    }
}
// 上下文角色
public class ShoppingCart {
    private final List<Item> items;
    private final PaymentMethod method;

    // 构造器注入支付方法
    public ShoppingCart(PayStrategy strategy){
        this.items = new ArrayList<>();
        this.method = new PaymentMethod(strategy);
    }

    void checkout(){
        int total = calculateTotal();
        if(method.pay(total)){
            System.out.println("Payment Successful!");
        } else{
            System.out.println("Payment failed.");
        }
    }
    
    // 计算购物车总价的方法...
}
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    // 用户输入信用卡信息以确定采用哪种支付策略
    System.out.print("Input full name: ");
    String fullName = scanner.nextLine();

    System.out.print("Input credit card number: ");
    String ccNum = scanner.nextLine();

    // 根据用户输入创建合适的支付策略对象，并传递给ShoppingCart构造函数。
    ShoppingCart cart = new ShoppingCart(new CreditCardPayment(fullName, ccNum));

    // 模拟添加商品到购物车...

    // 开始结算流程123
    cart.checkout(); 
}